package com.functest.jpwise

import com.functest.jpwise.core.ParameterValue
import com.functest.jpwise.core.TestParameter

/**
 * @author: DavydovMD
 * Date: 18.06.13
 * Time: 13:51
 */
class GeneratedValue implements ParameterValue {
    final private Closure generator;
    TestParameter parentParameter = null
    String name

    GeneratedValue(String name, Closure generator) {
        super()
        this.name = name;
        this.generator = generator
    }

    @Override
    Object get() {
        generator.call()
    }

    @Override
    boolean isCompatibleWith(ParameterValue thatValue) {
        (parentParameter == null) || parentParameter.areCompatible(this, thatValue)
    }


    @Override
    String toString(){
       "GeneratedValue{${parentParameter?.name}:$name}"
    }
}
